package entility;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class JobImpl implements Job{

	/**
	 * 
	 */
	private static final long serialVersionUID = -1298874117877687170L;

	private String head; //use to store the file name
	
	public String getOrigin() {
		return origin;
	}

	
	

	private List<String> data;
	private Map<Machine,List<Range>> listaIntervalos;
	private String method;
	private String origin;

	private List<Integer> dataInteger;
	

	
	@Override
	public String toString() {
		return "JobImpl [head=" + head + ", data=" + data
				+ ", listaIntervalos=" + listaIntervalos + ", method=" + method
				+ ", origin=" + origin + ", dataInteger=" + dataInteger + "]";
	}




	public JobImpl(String origin){
		
		this.origin = origin;
		
	}

	
	
	
	@Override
	public String getHead() {
		// TODO Auto-generated method stub
		return head;
	}

	@Override
	public List<String>getData() {
		// TODO Auto-generated method stub
		return data;
	}



	@Override
	public void setHead(String head) {
		this.head = head;
	}

	@Override
	public void setData(List<String> data) {

		this.data = data;	

	}

	@Override
	public void setMethod(String method) {
		this.method = method;
	}

	@Override
	public String getMethod() {
		// TODO Auto-generated method stub
		return method;
	}

	@Override
	public void setData(Machine me) {
		String str = me.ip+":"+me.port;
		List<String> data = new ArrayList<String>();
		data.add(str);
		this.setData(data);

	}
	
	

	@Override
	public List<Machine> getMachineList() {

		List<Machine> machines = new ArrayList<Machine>();

		for(String s:this.getData())
		{	
			String mac[] = s.split(":");
			machines.add(new Machine( mac[0], Integer.parseInt(mac[1])));

		}


		return machines;
	}

	@Override
	public void setData(String message) {
		
		this.data = new ArrayList<String>();
		this.data.add(message);
		
		
	}
	
	public List<Integer> getArray()
	{
		ArrayList< Integer> array = new ArrayList<Integer>();
		for(String S:this.data)
			array.add(Integer.parseInt(S));
			
		return array;
		
	}
	
	
	public Job clone()
	{
		
		Job job = new JobImpl(this.getOrigin());
		job.setData(new ArrayList<String>(this.data));
		if(this.head != null)
			job.setHead(this.head);
		
		job.setMethod(this.method);
		return job;
		
	}

	@Override
	public void Origin(String origin) {
		this.origin = origin;
	}

	@Override
	public List<Integer> getIntData() {
		return this.dataInteger;
	}

	@Override
	public void setDataInt(List<Integer> ids) {
		this.dataInteger = ids;
	}

	@Override
	public void setData(Map<Machine, List<Range>> listaIntervalos) {
		// TODO Auto-generated method stub
		this.listaIntervalos = listaIntervalos;
	}
	
	
	public Map<Machine, List< Range >> getRangeMap()
	{
		return this.listaIntervalos;
	}
	





}
